"""
演示Python的工厂模式
"""


class Person:
    pass


class Worker(Person):
    pass


class Student(Person):
    pass


class Teacher(Person):
    pass


class PersonFactory:
    """
    Person的工厂类，用来创建其子类
    """

    def get_person(self, p_type: str):
        """
        创建Person的子类对象
        :param p_type: 创建对象类型，传入w创建Worker对象，传入s创建Student对象，传入其他创建Teacher对象
        :return: Person的子类对象
        """
        if p_type.lower() == "w":
            return Worker()
        elif p_type.lower() == "s":
            return Student()
        else:
            return Teacher()


pf = PersonFactory()
worker = pf.get_person("W")
stu = pf.get_person("s")
teacher = pf.get_person("t")

print(f"worker类型：{type(worker)}, stu类型：{type(stu)}, teacher类型：{type(teacher)}")
